const settingService = require('./setting')

const get = async () => {
  const options = await settingService.getMulti([
    'TypeOptions',
    'HourPriceRangeOptions',
    'DayPriceRangeOptions',
    'MonthPriceRangeOptions',
    'HouseTypeOptions',
    'HouseStyleOptions',
    'HouseDecorateStyleOptions',
    'AreaRangeOptions',
    'UsageOptions',
    'FacilityOptions',
    'ScenicOptions',
    'DistrictOptions',
    'CapacityOptions'
  ])

  const toOption = (key) => {
    return (value, i) => {
      if (key === 'TypeOptions') {
        return { label: value, value: i + 1 }
      } else {
        return { label: value, value: value }
      }
    }
  }
  const [
    typeOptions,
    hourPriceOptions,
    dayPriceOptions,
    monthPriceOptions,
    houseTypeOptions,
    houseStyleOptions,
    houseDecorateStyleOptions,
    areaOptions,
    usageOptions,
    facilityOptions,
    scenicOptions,
    districtOptions,
    capacityOptions
  ] = options.map((opt) => opt.value.split(',').map(toOption(opt.key)))
    
  const filters = {
    type: {
      options: typeOptions,
      key: 'type',
      title: '空间类型'
    },
    dayPriceRange: {
      options: dayPriceOptions,
      key: 'dayPriceRange',
      title: '日价格'
    },
    monthPriceRange: {
      options: monthPriceOptions,
      key: 'monthPriceRange',
      title: '租金'
    },
    hourPriceRange: {
      options: hourPriceOptions,
      key: 'hourPriceRange',
      title: '小时价格'
    },
    houseType: {
      options: houseTypeOptions,
      type: 'houseType',
      title: '房型'
    },
    houseStyle: {
      options: houseStyleOptions,
      type: 'houseStyle',
      title: '类型'
    },
    houseDecorateStyle: {
      options: houseDecorateStyleOptions,
      key: 'houseDecorateStyle',
      title: '装修风格'
    },
    areaRange: {
      options: areaOptions,
      key: 'areaRange',
      title: '面积'
    },
    usage: {
      options: usageOptions,
      key: 'usage',
      title: '用途'
    },
    facility: {
      options: facilityOptions,
      key: 'facility',
      title: '设施'
    },
    scenic: {
      options: scenicOptions,
      key: 'scenic',
      title: '景点'
    },
    district: {
      options: districtOptions,
      key: 'district',
      title: '区域'
    },
    capacityRange: {
      options: capacityOptions,
      key: 'capacityRange',
      title: '人数'
    }
  }
  return filters
}
module.exports = {
  get
}